<?php

namespace App\Http\Controllers\Wap;

use App\Util\Result;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Model\Card;
use App\Model\Member;
use App\Model\Picture;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;

class FaceController extends Controller
{
    public function __construct(Request $request){
        $this->request = $request;
//        $this->openid = session('wechat_user')['id'];
//        $this->openid = 'oiYTrwfH-VLzRn8OkLsn_knKv3qM';
//        if (!empty($this->openid)) {
//            $this->memberId = Member::where('openid',$this->openid)->pluck('id');
//        }
    }

    /**
     * 已激活电子卡列表
     * czs
     */
    public function index(){
//        $res = Card::activeEcard($this->memberId,$limit=30)->getData();
        return view('wap.face.index');
//            ->with('res',$res);
    }

    public function faceSave() {
        $input = $this->request->all();
        $input['created_at'] = time();
        if (empty($input['std_no'])) {
            return Result::failure()->setmsg('请输入学号')->getResult();
        }
        if (empty($input['name'])) {
            return Result::failure()->setmsg('请输入姓名')->getResult();
        }
        if (empty($input['img'])) {
            return Result::failure()->setmsg('请上传图片')->getResult();
        }
        $res = DB::table('faces')->insert($input);
        if($res !== false){
            return Result::success('添加成功')->getResult();
        }
        return Result::failure()->getResult();
    }
}
